package com.cvmars.jianyou.module.activity;

import android.content.pm.ActivityInfo;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.cvmars.jianyou.R;
import com.cvmars.jianyou.module.adapter.HomeTaskTypeAdapter;
import com.cvmars.jianyou.module.base.BaseActivity;
import com.cvmars.jianyou.module.listener.PermissionListener;
import com.cvmars.jianyou.utils.KeyBoradUtils;
import com.cvmars.jianyou.utils.ToastUtils;
import com.zhihu.matisse.Matisse;
import com.zhihu.matisse.MimeType;
import com.zhihu.matisse.engine.impl.GlideEngine;
import com.zhihu.matisse.filter.Filter;

import java.util.ArrayList;
import java.util.List;

public class TaskPulishActivity extends BaseActivity {

    RecyclerView listTask;

    HomeTaskTypeAdapter taskTypeAdapter;

    boolean isFirstTitle = true;

    EditText editTextTitle;
    TextView editTextTitle2;
    TextView txtSure;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task_pulish);

        listTask = findViewById(R.id.list_task);
        editTextTitle = findViewById(R.id.ed_title);
        txtSure = findViewById(R.id.txt_sure);
        listTask.setLayoutManager(new LinearLayoutManager(
                this,LinearLayoutManager.VERTICAL,false));

        List<String> data = new ArrayList<>();
        data.add("1");
        data.add("1");
        data.add("1");
        taskTypeAdapter = new HomeTaskTypeAdapter(R.layout.item_task_step,data);
        View view = LayoutInflater.from(this).inflate(R.layout.header_task_publish,null);
        taskTypeAdapter.addHeaderView(
                view);

        editTextTitle2 = view.findViewById(R.id.ed_title);
        listTask.setAdapter(taskTypeAdapter);
        editTextTitle.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {


            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

                if(charSequence.length() > 0){

                    txtSure.setTextColor(ContextCompat.getColor(TaskPulishActivity.this,R.color.color666));
                }else{

                    txtSure.setTextColor(ContextCompat.getColor(TaskPulishActivity.this,R.color.color999));
                }

            }

            @Override
            public void afterTextChanged(Editable editable) {


            }
        });
    }

    public void onPublish(View view){


        if(TextUtils.isEmpty(editTextTitle.getText().toString())){

            ToastUtils.show("请输入任务标题");
            return;
        }
        if(isFirstTitle){
            txtSure.setText("发布");
            listTask.setVisibility(View.VISIBLE);
            findViewById(R.id.ll_title).setVisibility(View.GONE);
            isFirstTitle = false;
            editTextTitle2.setText(editTextTitle.getText().toString());
            KeyBoradUtils.closeKeyborad(editTextTitle,this);
        }else{


        }
//        checkMyPermission(new PermissionListener(PermissionListener.PHOTO) {
//            @Override
//            public void onPermissionClick() {
//
//                Matisse.from(TaskPulishActivity.this)
//                        .choose(MimeType.allOf())
//                        .countable(true)
//                        .maxSelectable(1)
//                        .restrictOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED)
//                        .thumbnailScale(0.85f)
//                        .imageEngine(new GlideEngine())
//                        .forResult(1);
//            }
//        });

    }
}
